package chenbi.renthouse.controller;

import chenbi.renthouse.common.Result;
import chenbi.renthouse.controller.request.HousePageRequest;
import chenbi.renthouse.entity.House;
import chenbi.renthouse.service.IHouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/house")
public class HouseController {

    @Autowired
    IHouseService houseService;

//    @GetMapping("/list")
//    public Result list(){
//        List<House> houses = houseService.list();
//        return Result.success(houses);
//    }

//    查询所有房源
    @GetMapping("/list")
    public Result list() {
        List<House> houses = houseService.list();
        return Result.success(houses);
    }

    //    分页查询
    @GetMapping("/page")
    public Result page(HousePageRequest housePageRequest){
        return Result.success( houseService.page(housePageRequest));

    }

    //    新增房源
    @PostMapping("/save")
    public Result save(@RequestBody House house){
        houseService.save(house);
        return Result.success();
    }


}
